package me.json.other;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;

public class CountryFactroy {

    private static final String JSON_FILE = "other/country_temp.json";

    public static void make() {
        try {
            File file = new File(JSON_FILE);
            if (file.exists() && file.isFile()) {
                ObjectMapper mapper = new ObjectMapper();
                JsonFactory jsonFactory = new JsonFactory();
                JsonGenerator jsonGenerator = jsonFactory.createGenerator(file, JsonEncoding.UTF8);
                mapper.writeValue(jsonGenerator, makeProvinces());

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        make();
        //        parser();
    }

    private static List<Province> makeProvinces() {
        List<Province> provinces = new ArrayList<Province>();

        List<City> tw = new ArrayList<City>();
        tw.add(new City("32", "台北市"));
        tw.add(new City("32", "高雄市"));
        tw.add(new City("32", "基隆市"));
        tw.add(new City("32", "台中市"));
        tw.add(new City("32", "台南市"));
        tw.add(new City("32", "新竹市"));
        tw.add(new City("32", "嘉义市"));
        tw.add(new City("32", "台北县"));
        tw.add(new City("32", "宜兰县"));
        tw.add(new City("32", "新竹县"));
        tw.add(new City("32", "桃园县"));
        tw.add(new City("32", "苗栗县"));
        tw.add(new City("32", "台中县"));
        tw.add(new City("32", "彰化县"));
        tw.add(new City("32", "南投县"));
        tw.add(new City("32", "嘉义县"));
        tw.add(new City("32", "云林县"));
        tw.add(new City("32", "台南县"));
        tw.add(new City("32", "高雄县"));
        tw.add(new City("32", "屏东县"));
        tw.add(new City("32", "台东县"));
        tw.add(new City("32", "花莲县"));
        tw.add(new City("32", "澎湖县"));
        provinces.add(new Province("32", "710000", "台湾省", tw));

        List<City> xg = new ArrayList<City>();
        xg.add(new City("33", "中西区"));
        xg.add(new City("33", "东区"));
        xg.add(new City("33", "九龙城区"));
        xg.add(new City("33", "观塘区"));
        xg.add(new City("33", "南区"));
        xg.add(new City("33", "深水涉区"));
        xg.add(new City("33", "黄大仙区"));
        xg.add(new City("33", "湾仔区"));
        xg.add(new City("33", "油尖旺区"));
        xg.add(new City("33", "离岛区"));
        xg.add(new City("33", "葵青区"));
        xg.add(new City("33", "北区"));
        xg.add(new City("33", "西贡区"));
        xg.add(new City("33", "沙田区"));
        xg.add(new City("33", "屯门区"));
        xg.add(new City("33", "大埔区"));
        xg.add(new City("33", "荃湾区"));
        xg.add(new City("33", "元朗区"));
        provinces.add(new Province("33", "810000", "香港特别行政区", xg));

        List<City> am = new ArrayList<City>();
        am.add(new City("34", "澳门半岛"));
        am.add(new City("34", "氹仔"));
        am.add(new City("34", "路环"));
        provinces.add(new Province("34", "820000", "澳门特别行政区", am));

        return provinces;
    }

}
